import 'package:flutter/material.dart';
import 'package:flutter_project/config/app_bar_view.dart';
import 'package:flutter_project/config/theme_color.dart';

class NoticeSetPage extends StatefulWidget {
  const NoticeSetPage({super.key});

  @override
  State<NoticeSetPage> createState() => _NoticeSetPageState();
}

class _NoticeSetPageState extends State<NoticeSetPage> {
  ValueNotifier<bool> isOpenNotice = ValueNotifier(false);
  ValueNotifier<bool> isNoTrouble = ValueNotifier(false);

  @override
  Widget build(BuildContext context) {
    return CommonAppWidget.navAppBar(
      title: '系统通知',
      childWidget: ListView(
        children: [
          getNoticeListItem('置顶通知', isOpenNotice),
          const SizedBox(
            height: 10,
          ),
          getNoticeListItem('消息免打扰', isNoTrouble),
        ],
      ),
    );
  }

  Widget getNoticeListItem(String title, ValueNotifier<bool> isOpenSwitch) {
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            title,
            style: TextStyle(color: ThemeColor.textColor),
          ),
          ValueListenableBuilder(
              valueListenable: isOpenSwitch,
              builder: (BuildContext context, bool isOpen, Widget? child) {
                return Switch(
                    inactiveTrackColor: Colors.white,
                    trackOutlineWidth: const MaterialStatePropertyAll(0.5),
                    value: isOpen,
                    onChanged: (bool res) {
                      isOpenSwitch.value = !isOpenSwitch.value;
                    });
              }),
        ],
      ),
    );
  }
}
